package com.example.home.hospital.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.home.R;
import com.example.home.government.acivity.AppealMainActivity;
import com.example.home.government.adapter.AppealMainAdapter;
import com.example.home.government.adapter.PatientIDCardAdapter;
import com.example.home.hospital.bean.AllCardBean;
import com.example.home.hospital.bean.HospitalListBean;
import com.example.home.tool.OKHttpTool;

public class PatientIDCard extends AppCompatActivity {
    private ImageView back;
    private ImageView add;
    private RecyclerView rcvCard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patient_i_d_card);
        initView();
        getAllCard();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getAllCard();
    }

    private void getAllCard() {
        OKHttpTool.doNetRequest("prod-api/api/hospital/patient/list",
                OKHttpTool.GET,
                AllCardBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        AllCardBean allCardBean = (AllCardBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                bindListData(allCardBean);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                }
        );
    }

    private void bindListData(AllCardBean allCardBean) {
        PatientIDCardAdapter patientIDCardAdapter = new PatientIDCardAdapter(PatientIDCard.this, allCardBean.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(PatientIDCard.this);
        rcvCard.setAdapter(patientIDCardAdapter);
        rcvCard.setLayoutManager(linearLayoutManager);
    }

    private void initView() {

        back = findViewById(R.id.back);
        add = findViewById(R.id.add);
        rcvCard = findViewById(R.id.rcv_card);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PatientIDCard.this.finish();
            }
        });

        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PatientIDCard.this,AddCardActivity.class);
                startActivity(intent);
            }
        });

    }
}